/**
 * 
 */
package stc.skymobi.ebus.runnable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import stc.skymobi.ebus.EventBus;


/**
 * @author hp
 *
 */
public class TaskOverflowWarning implements Runnable {

    private static final Logger logger = 
    	LoggerFactory.getLogger(TaskOverflowWarning.class);
    
	private	int		taskWarnThreshold = 500;
	private	long	selfCheckTimeout = 60 * 1000;
	private	EventBus	eventBus;
	private	long	lastCheckTime = 0;
	private	String	description;
	
	public TaskOverflowWarning(String desc) {
		this.description = desc;
	}
	
	public EventBus getEventBus() {
		return eventBus;
	}

	public void setEventBus(EventBus eventBus) {
		this.eventBus = eventBus;
	}
	
	public int getTaskWarnThreshold() {
		return taskWarnThreshold;
	}
	public void setTaskWarnThreshold(int taskWarnThreshold) {
		this.taskWarnThreshold = taskWarnThreshold;
	}
	public long getSelfCheckTimeout() {
		return selfCheckTimeout;
	}
	public void setSelfCheckTimeout(long selfCheckTimeout) {
		this.selfCheckTimeout = selfCheckTimeout;
	}
	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		
		try {
			long now = System.currentTimeMillis();
			
			if ( now - lastCheckTime >= selfCheckTimeout ) {
				lastCheckTime = now;
				if ( logger.isInfoEnabled() ) {
					logger.info("actor [" + this.description + "] active.");
				}
			}
			
//			ExecutorService exec = eventBus.getExecutorInCurrentThread();
//			
//			boolean	enabled = eventBus.contains(exec);
//	
//			if ( exec instanceof ThreadPoolExecutor ) {
//				int		taskCount = ((ThreadPoolExecutor )exec).getQueue().size();
//				
//				if ( taskCount > this.taskWarnThreshold ) {
//					if ( logger.isWarnEnabled() ) {
//						logger.warn("too manay task [" + taskCount + "] , and actor status [ " + enabled + "]");
//					}
//				}
//			}
		}
		catch (Exception e) {
			logger.error("run:", e);
		}
	}

}
